<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
</head>

<body>
    <div id='app'>
        <router-link to="/news/1">新闻</router-link>
        <router-link to="/music">音乐</router-link>
        <router-view></router-view>
    </div>
    <script src='https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js'></script>
    <script src="../js/vue-router.js"></script>

    <script>
        // 动态路由匹配,将路由地址中的参数拿到 $route是当前路由地址的信息对象
        const news = {
            template: `<div>新闻组件列表 -- {{$route.params.id}}</div>`
        }

        const music = {
            template: `<div>音乐组件列表</div>`
        }

        // 路由对象和路由规则
        const router = new VueRouter({
            routes: [{
                    path: '/',
                    redirect: '/music'
                },
                {
                    path: '/news/:id',
                    component: news
                },
                {
                    path: '/music',
                    component: music
                }
            ]
        })

        const vm = new Vue({
            el: '#app',
            data: {

            },
            methods: {},
            // 将路由实例挂载到Vue实例
            router
        })
    </script>
</body>

</html>